package de.hmm.hwip.configuration.services;

import java.util.Hashtable;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

import android.util.Log;

import de.hmm.hwip.configuration.api.ISpotConf;
import de.hmm.hwip.configuration.api.ISystemConf;
import de.hmm.hwip.configuration.api.ISystemDeviceConf;
import de.hmm.hwip.configuration.spot.SpotImpl;
import de.hmm.hwip.configuration.sysdevice.SystemDeviceImpl;
import de.hmm.hwip.configuration.system.SystemConfImpl;

/**
 * OSGi Service to provide Configuration service
 * 
 * @author johannes mendel
 * @version 28.10.2012
 */
public class Activator implements BundleActivator {
	
	/** Class identifier to debug **/
	final String TAG = "Config Service Activator";
	
	/**
	 * osgi System Device configuration service interface
	 */
	private ISystemDeviceConf sysDevService;
	
	/**
	 * osgi Spot configuration service interface
	 */
	private ISpotConf spotService;
	
	/**
	 * osgi Spot configuration service interface
	 */
	private ISystemConf systemService;
	
	@Override
	public void start(BundleContext context) throws Exception {
		Log.i(TAG, "==========> Config Service started <==========");
		
		sysDevService = new SystemDeviceImpl();
		spotService = new SpotImpl();
		systemService = new SystemConfImpl();
		
        // register the sysdev cof service
        Hashtable<String, Object> sysdevparams = new Hashtable<String, Object>();
        sysdevparams.put( org.osgi.framework.Constants.SERVICE_PID, ISystemDeviceConf.class.getName());
        sysdevparams.put( org.osgi.framework.Constants.SERVICE_DESCRIPTION, "Provides System Device Conf Service");
        context.registerService(ISystemDeviceConf.class.getName(), sysDevService, sysdevparams);

        // register the spot conf service
        Hashtable<String, Object> spotparams = new Hashtable<String, Object>();
        spotparams.put( org.osgi.framework.Constants.SERVICE_PID, ISpotConf.class.getName());
        spotparams.put( org.osgi.framework.Constants.SERVICE_DESCRIPTION, "Provides Spot Conf Service");
        context.registerService(ISpotConf.class.getName(), spotService, spotparams);
        
     // register the spot conf service
        Hashtable<String, Object> systemparams = new Hashtable<String, Object>();
        systemparams.put( org.osgi.framework.Constants.SERVICE_PID, ISystemConf.class.getName());
        systemparams.put( org.osgi.framework.Constants.SERVICE_DESCRIPTION, "Provides System Conf Service");
        context.registerService(ISystemConf.class.getName(), systemService, systemparams);
	}

	@Override
	public void stop(BundleContext arg0) throws Exception {
		Log.i(TAG, "<========== !!! Config Service stopped !!! ==========>");

	}

}
